<?php


namespace app\admin\behavior;
/**
 * 测试标签内
 * Class AopTest
 * @package app\admin\behavior
 * 使用
 * eg：
 *          $params1=array(1,1,1,3);
 * $res = \think\Hook::listen('api_init',$params1);
 * $params2=array(1,1,1,3);
 * \think\Hook::listen('api_end',$params2);
 *
 */
class AopPermissions
{
    public function aopPermissions(&$params)
    {
        $m = request()->module();
        $c = request()->controller();
        $a = request()->action();
        $currUrl = strtolower("/" . $m . "/" . $c . "/" . $a);//当前访问路径
        $userinfo = getCurrLoginSession();
        $isSupperManager = isSupperManagerForSession();
        $allPowerList = $userinfo['systemAllPower'];//系统所有权限详细数组
        $systemAllPowerPath = $userinfo['systemAllPowerPath'];//系统所有权限PATH数组
        $currPowerList = $userinfo['CurrPower'];//当前权限
        if ($isSupperManager == 0) {//不是超级管理员权限
            if (in_array($currUrl, $systemAllPowerPath))//当前地址在所有需要判断权限的地址范围内
            {
                //把前端地址转换成权限ID
                $currPowerID = 0;//当前url对应的权限ID
                if (isset($allPowerList[$currUrl]) && !empty($allPowerList[$currUrl])) {
                    $currPowerID = $allPowerList[$currUrl]['id'];
                }
                if (empty($currPowerID)) {
                    echo '对不起你无权访问该功能';
                    exit;
                }
                if (!in_array($currPowerID, $currPowerList)) {
                    echo '对不起你无权访问该功能';
                    exit;
                }
            }
        }
    }

    //绑定api结束
    public function apiEnd(&$params)
    {
        print_r($params);
    }
}